package com.itheima.controller;

import com.itheima.dto.PageUser;
import com.itheima.dto.SysUserDTO;
import com.itheima.mapper.SysUserMapper;
import com.itheima.result.PageData;
import com.itheima.result.R;
import com.itheima.service.SysUserService;
import com.itheima.vo.SysUserVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @projectName: kafka
 * @package: com.itheima.controller
 * @className: SysUserController
 * @author: Eric
 * @description: TODO
 * @date: 2023/9/23 14:44
 * @version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/sys_user")
@AllArgsConstructor
public class SysUserController {
    private final SysUserService sysUserService;

    @GetMapping("/list")
    public R<PageData> page(PageUser pageUser){
        PageData pageData = sysUserService.page(pageUser);
        return R.success(pageData);
    }

    @PostMapping("/add")
    public R<?> creatUser(@RequestBody SysUserDTO sysUserDTO){
        System.out.println("-------------sysUserDTO------------------"+sysUserDTO);
        sysUserService.creatUser(sysUserDTO);
        return R.success();
    }

    @GetMapping("/del")
    public R<?> deleteUser(String id){
        sysUserService.deleteUser(id);
        return R.success();
    }

    @GetMapping("/rowInfo")
    public R<SysUserVO> queryUserInfo(String id){
        SysUserVO sysUserVO = sysUserService.queryUserInfo(id);
        return R.success(sysUserVO);
    }

    @PostMapping("/update")
    public R<?> updateUser(@RequestBody SysUserDTO sysUserDTO){
        sysUserService.updateUser(sysUserDTO);
        return R.success();
    }
}
